package cn.apthink.solon;

import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Filter;
import org.noear.solon.core.handle.FilterChain;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LoggingFilter implements Filter {

	public void handle(Context ctx) throws Throwable {
		log.info("=>LoggingHandler ip: "+ ctx.realIp() + " "+ctx.remoteIp());
		log.info("=>LoggingHandler url: "+ ctx.url());
		log.info("=>LoggingHandler path: "+ ctx.path());
		log.info("=>LoggingHandler userAge: "+ ctx.userAgent());
		log.info("=>LoggingHandler header: "+ ctx.headerMap());
		log.info("=>LoggingHandler query: "+ ctx.queryString());
		log.info("=>LoggingHandler params: "+ ctx.paramMap().toValuesMap().toString());
		log.info("=>LoggingHandler body: "+ ctx.body());
	}

	@Override
	public void doFilter(Context ctx, FilterChain chain) throws Throwable {
        chain.doFilter(ctx);
        
        handle(ctx);
        log.info("==>doFilter: FilterChain=" + chain.toString() + " Context:" + ctx.toString());	
	}

}
